APM.ConfigTestController = Ember.Controller.extend({
	init: function(){
		this._super();
		this.getDateInterval();
	},
	form: {
		name: "",
		isDedicate: true,
		date: new Date(2014, 3, 1),
		aaa: "",
		bbb: ""
	},

	hypervisors: Ember.A([
		{
			"displaytext": "Hyperv",
			"value": "Hyperv"
		},
		{
			"displaytext": "KVM",
			"value": "KVM"
		},
		{
			"displaytext": "XenServer",
			"value": "XenServer"
		},
		{
			"displaytext": "VMware",
			"value": "VMware"
		},
		{
			"displaytext": "BareMetal",
			"value": "BareMetal"
		},
		{
			"displaytext": "Ovm",
			"value": "Ovm"
		},
		{
			"displaytext": "LXC",
			"value": "LXC"
		}
	]),

    testArray: [
        {
            label: 'c++',
            value: 'c++'
        },
        {
            label: 'java',
            value: 'java'
        },
        {
            label: 'php',
            value: 'php'
        },
        {
            label: 'coldfusion',
            value: 'coldfusion'
        },
        {
            label: 'javascript',
            value: 'javascript'
        },
        {
            label: 'asp',
            value: 'asp'
        },
        {
            label: 'ruby',
            value: 'ruby'
        },
        {
            label: 'python',
            value: 'python'
        },
        {
            label: 'c',
            value: 'c'
        },
        {
            label: 'scala',
            value: 'scala'
        },
        {
            label: 'groovy',
            value: 'groovy'
        },
        {
            label: 'haskell',
            value: 'haskell'
        },
        {
            label: 'perl',
            value: 'perl'
        }
    ],

    getDateInterval: function(){
		var ctrl = this;
		function daytime(){
		var n;
		var now = new Date(new Date() - timeD_value);
		var hh = now.getHours();
		var mm = now.getMinutes();
		var ss = now.getSeconds();
		var yy= now.getFullYear();
		var MM= now.getMonth()+1;
		var rr= now.getDate();
		var ww= now.getDay();
		var days= ["日","一","二","三","四","五","六" ]
		n = yy+"年" +MM +"月" + rr+"日  " +hh+":"+mm+":"+ss+"  星期"+days[ww];
		return n;
		}
		this.getDateTimer = setInterval(function(){
			ctrl.set("localTime", daytime());
		}, 1000);
    },

	checkFormValid: function(){
		var form = this.get("form");

		if( form.name == "" ){
			this.set("formTip", "集群名不能为空.");
			return false;
		}
		this.set("formTip", null);
		return true;
	},

	actions: {
		save: function(){
			if( !this.checkFormValid() ){
				return;
			}
			var ctrl = this;
			var form = this.get("form");

			ctrl.set("addDisabled", true);

			this.store.ajax("POST", "config/base", {
				name: form.name,
				hypervisor: form.hypervisor,
				isDedicate: form.isDedicate,
				date: +form.date,
				aaa: form.aaa
			})
			.then(function(response){
				//todo: 保存成功逻辑
				ctrl.set("addDisabled", false);
			}, function(){
				ctrl.set("addDisabled", false);
			});
		},
		reset: function(){
			clearInterval(this.getDateTimer);
		}
	}
});